class MobilesController < ApplicationController
  # GET /companies
  # GET /companies.xml
  
  def index
    @parent = :index
    @companies = Company.all
    @activeComputerSize = 0
    @inactiveComputerSize = 0
    @operationComputerSize = 0
    @allComputerSize = 0
    
    # allComputers
    allComputers = Computer.find(:all)
    if (allComputers != nil) 
      @allComputerSize = allComputers.size
    end

    # activeComputers
    activeComputers = Computer.find(:all, :conditions => ["status = 1"])
    if (activeComputers != nil) 
      @activeComputerSize = activeComputers.size
    end
   
    # inactiveComputers
    inactiveComputers = Computer.find(:all, :conditions => ["status = 0"])
    if (inactiveComputers != nil) 
      @inactiveComputerSize = inactiveComputers.size
    end
   
    # operationComputers
    operationComputers = Computer.find(:all, :conditions => ["status = 2"])
    if (operationComputers != nil) 
      @operationComputerSize = operationComputers.size
    end
   
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @companies }
    end
    
  end
  
  def showRooms
    @title = "Rooms"
    @parent = :index
    @company = Company.find(params[:id])
    @rooms = @company.rooms
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @rooms }
    end
  end
  
  def showComputers
    @title = "Computers"
    @parent = :showRooms
    @room = Room.find(params[:id])
    @parentId = @room.company.id
    @computers = @room.computers
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @computers }
    end
  end
  
  def showOperations
    @title = "Operations"
    @parent = :showComputers
    @computer = Computer.find(params[:id])
    @parentId = @computer.room.id
    @operations = @computer.operations
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @operations }
    end
  end
  
  def allComputers
    @title = "All computers"
    @parent = :index
    @computers = Computer.all
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @computers }
    end
  end

  def inactiveComputers
    @title = "Inactive"
    @parent = :index
    @computers = Computer.find(:all, :conditions => ["status = 0"])
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @computers }
    end
  end
  
  def activeComputers
    @title = "Active"
    @parent = :index
    @computers = Computer.find(:all, :conditions => ["status = 1"])
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @computers }
    end
  end
  
  def operationComputers
    @title = "Operation"
    @parent = :index
    @computers = Computer.find(:all, :conditions => ["status = 2"])
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @computers }
    end
  end
  
end
